<template>
  <div class="form-page">
    <el-form ref="form" size="mini" :model="form" label-width="30%" :rules="formRules">
      <div>
        <template v-if="channel">
          <el-form-item label="序号：">
            <div style="flex: 1">
              {{ tableStatus ? tableStatus.sortNum : addSortNum ? addSortNum : '' }}
            </div>
          </el-form-item>
        </template>
      </div>
      <div
        v-for="(tableField, index) in preHandle(tableFieldList)"
        :key="index"
        :class="{
          'columns-hover': ['1', '2'].includes(tableField.type),
        }"
      >
        <template v-if="tableField.type === '1'">
          <el-form-item
            v-if="(channel && channel == 'list') || tableField.variable != 'SerialNumber'"
            :label="`${tableField.variableName}${tableField.entry ? '(' + tableField.entry + ')' + '：' : '：'}`"
            :prop="tableField.variable"
          >
            <div style="flex: 1">
              <fieldForm
                v-model="form[tableField.variable]"
                :table-field="tableField"
                :tableFieldList="tableFieldList"
                :table-status="tableStatus"
              />
              <div v-if="tableStatus && tableStatus.isStatus === '1'" class="check-font">
                {{ tableField.questionContent ? tableField.questionContent : '' }}
              </div>
            </div>
            <!-- 右侧操作按钮 -->
            <div class="form-tools">
              <!-- 研究者批注 -->
              <i
                :class="[
                  'tool-note',
                  handleNotesStatus(tableField) === 1 ? 'el-icon-notebook-2' : 'el-icon-edit-outline',
                  handleNotesStatus(tableField) === '' ? 'colorDark' : '',
                ]"
                @click="handleNotes(tableField)"
              >
              </i>
              <div class="checkbox">
                <el-checkbox
                  :disabled="
                    !tableStatus ||
                    tableStatus.isLapse !== '1' ||
                    tableStatus.isStatus === '1' ||
                    tableStatus.frozen > 1 ||
                    !permissionController('pi::signature')
                  "
                  v-model="form[`$${tableField.variable}--sign`]"
                />
              </div>
              <div
                v-for="(item, index) in handleTools(tableField.fromDataChecksetupDTO)"
                :class="`tools-checkbox-${item.enable}`"
                :key="index"
              >
                <el-checkbox
                  :disabled="item.disabled || item.enable === 0|| item.enable === '0'"
                  v-model="form[`$${tableField.variable}--${item.tag}`]"
                />
              </div>
              <div
                :class="`question question-${handleQuestionStatus(tableField)}`"
                @click="handleQuestion($event, tableField)"
              >
                &nbsp;
              </div>
            </div>
          </el-form-item>
        </template>
        <template v-else-if="tableField.type === '2'">
          <el-form-item :label="`${tableField.variableName}`"> </el-form-item>
        </template>

        <template v-else-if="tableField.type === '3'">
          <!-- 表格表单 -->
          <formTable
            v-if="show"
            v-model="form[tableField.embeddedTableKey]"
            :table-field="tableField"
            :table-status="tableStatus"
            :checkboxed="checkboxed"
            :columns="embeddedTableRendering[tableField.embeddedTableKey]"
            :embedded-table="embeddedTable && embeddedTable[tableField.embeddedTableKey]"
            @delete="(embeddedTableKey, index) => $emit('delete', embeddedTableKey, index)"
            @add-inner="embeddedTableKey => $emit('add-inner', embeddedTableKey)"
          ></formTable>
        </template>
      </div>
    </el-form>
    <el-dialog
      title="研究者批注"
      :visible.sync="dialogNotesVisible"
      :width="dataNotes && dataNotes.length > 0 ? '800px' : '450px'"
      :destroy-on-close="true"
      :append-to-body="true"
    >
      <notes
        size="mini"
        type="2"
        :table-status="tableStatus"
        :table-data="dataNotes"
        @close="handleCloseNotes"
        :ex-params="exParams"
      />
    </el-dialog>
    <el-dialog
      title="质疑列表"
      width="800px"
      :visible.sync="dialogQuestionVisible"
      :destroy-on-close="true"
      :append-to-body="true"
      :close-on-click-modal="false"
      :before-close="closeDialogQuestion"
    >
      <question
        v-if="dialogQuestionVisible"
        :table-status="tableStatus"
        :table-field="targetTableField"
        @create="createQuestion"
        :queryType="queryType"
        :dialogQuestionVisible="dialogQuestionVisible"
        :queryListData="queryListData"
        style="height: 600px; overflow: auto"
      />
    </el-dialog>
    <el-dialog
      title="增加质疑"
      :visible.sync="dialogAddQuestionVisible"
      width="550px"
      :destroy-on-close="true"
      :append-to-body="true"
    >
      <add-question
        :queryType="queryType"
        :table-status="tableStatus"
        :table-field="targetTableField"
        @callback="
          () => {
            dialogAddQuestionVisible = false
            upgrade()
          }
        "
      />
    </el-dialog>
  </div>
</template>

<script>
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
import fieldForm from './components/field-forms.vue'
import formTable from './components/form-table.vue'
import Notes from '../notes.vue'
import Question from '../question.vue'
import AddQuestion from '../add-question.vue'
import { permissionController } from '@/utils/index'

export default {
  props: {
    tableStatus: {
      type: Object,
      default: () => {},
    },
    tableFieldList: {
      type: Array,
      default: () => [],
    },
    tableFieldRules: {
      type: Object,
      default: function () {
        return {}
      },
    },
    embeddedTable: {
      type: [Object, Array],
    },
    tableFieldConfig: {
      type: Object,
      default: () => {},
    },
    ocr: {
      type: Array,
      default: () => [],
    },
    fromDataNormal: {
      type: [Object, Array],
    },
    embeddedTableRendering: {
      type: Object,
      default: () => {},
    },
    channel: {
      type: String,
      default: () => '',
    },
    originSubjectData: {
      type: [Object, Array],
    },
    isAddEm: {
      type: Boolean,
    },
    isAdd: {
      type: Boolean,
    },
    isAddList: {
      type: Boolean,
    },
    checkboxed: {
      type: Boolean,
    },
    addSortNum: {
      type: Number,
    },
  },
  data() {
    return {
      form: {},
      formRules: {},
      dialogNotesVisible: false,
      dataNotes: new Array(),
      exParams: {},
      targetTableField: null,
      dialogQuestionVisible: false,
      dialogAddQuestionVisible: false,
      show: true,
      embeddedTableList: [],
      queryType: '1',
      queryListData: [],
    }
  },
  components: { fieldForm, formTable, Notes, Question, AddQuestion },
  computed: {
    ...mapState({
      subjectInfo: state => state.treatment.subjectInfo,
      audits: state => state.treatment.audits,
      visit: state => state.treatment.visit,
      table: state => state.treatment.table,
      relations: state => state.treatment.relations,
    }),
    ...mapGetters({
      findRole: 'treatment/findRole',
    }),
  },
  watch: {
    form: {
      handler: function (val) {
        if (this.fromDataNormal && Object.keys(this.fromDataNormal).length > 0) {
          // 实验室
          this.handleLaboratory(val)
        }
        // 同步数据
        this.handleSynchronize(val)
        // 行控制
        this.handleDisplay(this.tableFieldList, val)
        
      },
      deep: true,
    },
    tableFieldList: {
      handler: function (val) {
        if (val && val.length > 0) {
          this.handleMainTableValue(val)
          if (this.fromDataNormal && this.fromDataNormal.length > 0) {
            this.handleSemblance()
          }
        }
      },
      immediate: true,
    },
    tableFieldRules: {
      handler: function (val) {
        setTimeout(() => {
          this.formRules = val
          this.$nextTick(() => {
            this.$refs.form.clearValidate()
          })
        }, 100)

          
      },
      immediate: true,
    },
    originSubjectData: {
      handler: function (val) {
        if (val) {
          this.tableFieldList &&
            this.tableFieldList.forEach(tableField => {
              const {
                type,
                embeddedTableKey,
                embeddedTableType,
                embeddedTableModuleName,
                embeddedTableVariableMapping,
              } = tableField
              if (type === '3') {
                this.reloadEmbeddedTable(
                  embeddedTableKey,
                  {
                    embeddedTableType,
                    embeddedTableModuleName,
                    embeddedTableVariableMapping,
                  },
                  true
                )
              }
            })
        }
      },
      immediate: true,
    },
  },
  mounted() {
    setTimeout(() => {
      this.handleSpecify(this.form)
    }, 100)
  },
  methods: {
    permissionController,
    ...mapActions('eCRFDetail', ['getEmbeddedTable', 'annotationList', 'getQueryListAPI']),
    ...mapMutations({
      upgrade: 'treatment/upgrade',
    }),
    handleNotesStatus(tableField) {
      if (!this.permissionController('crf::form::data::annotation')) {
        return ''
      }
      if (this.tableStatus && tableField.formFieldId) {
        if (this.tableStatus.isLapse === '1' && this.tableStatus.frozen === '1') {
          return tableField.endorse
        } else {
          return tableField.endorse !== 0 ? tableField.endorse : ''
        }
      } else {
        return ''
      }
    },

    handleSemblance() {
      const fromDataNormal = this.fromDataNormal[0]
      const { labCheckDetailTable, checkProjectVariable, unitVariable, upVariable, floorVariable } = fromDataNormal
      const columns = this.embeddedTableRendering[labCheckDetailTable]
      columns.forEach(object => {
        if ([checkProjectVariable, unitVariable, upVariable, floorVariable].includes(object.variable)) {
          object.variableType = '200'
        }
      })
    },
    handleMainTableValue(tableFieldList) {
      tableFieldList.forEach(tableField => {
        const { variable, variableType, variableValue, defaultValue, cra, dm, pm, mm, pi } = tableField
        let value
        if (variableType === '20') {
          if (this.tableStatus) {
            if (variableValue) {
              value = variableValue.split(',')
            } else {
              value = []
            }
          } else {
            if (variableValue) {
              value = variableValue.split(',')
            } else {
              if (defaultValue) {
                value = defaultValue.split(',')
              } else {
                value = []
              }
            }
          }
        } else {
          if (this.tableStatus) {
            value = variableValue
            if (value) {
              this.$set(this.form, variable, variableValue)
            }
          } else {
            if (variableValue) {
              value = variableValue
            } else {
              value = defaultValue || ''
            }
          }
        }
        if (value) {
          this.$set(this.form, variable, value)
        }
        this.handleAudits(variable, 'cra', cra === 2)
        this.handleAudits(variable, 'dm', dm === 2)
        this.handleAudits(variable, 'pm', pm === 2)
        this.handleAudits(variable, 'mm', mm === 2)
        this.handleAudits(variable, 'pi', pi === 2)
      })
    },
    handleUpdateEmbeddedTable(embeddedTableName, data) {
      const array = (this.embeddedTable && this.embeddedTable[embeddedTableName]) || []
      if (array && array.length > 0) {
        array.forEach((object, index) => {
          this.$set(object, 'tableFieldList', data[index])
        })
      } else {
        data &&
          data.forEach(tableFieldList => {
            array.push({ tableFieldList })
          })
      }
      this.$emit('handleEmbedded', JSON.parse(JSON.stringify(array)))
    },
    handleUpdateEmbeddedTableRendering(embeddedTableName, data) {
      const array = data[0]
      const columns = this.embeddedTableRendering[embeddedTableName]
      columns.forEach(column => {
        const target = array.filter(item => item.variable == column.variable)[0]
        if (target) {
          column.variableType = target.variableType
        }
      })
    },
    // 内嵌表单解析
    handleSpecify(form) {
      this.tableFieldList &&
        this.tableFieldList.forEach(tableField => {
          const { type, embeddedTableKey, embeddedTableType, embeddedTableModuleName, embeddedTableVariableMapping } =
            tableField
          if (type === '3') {
            this.reloadEmbeddedTable(
              embeddedTableKey,
              form,
              {
                embeddedTableType,
                embeddedTableModuleName,
                embeddedTableVariableMapping,
              },
              true
            )
          }
        })
    },
    // 内嵌表数据处理
    findEmbeddedTable(params, toText) {
      const data = {
        ...params,
        visitTableId: this.isAddEm ? this.table.visitTableId : this.table.id,
      }
      this.getEmbeddedTable({ data }).then(res => {
        if (res.code === 200) {
          if (res.data instanceof Array && res.data.length > 0) {
            this.handleUpdateEmbeddedTable(params.embeddedTableName, res.data)
            toText && this.handleUpdateEmbeddedTableRendering(params.embeddedTableName, res.data)
            this.show = false
            this.$nextTick(() => {
              this.show = true
            })
          }
        }
      })
    },
    // 重新渲染表单
    reloadEmbeddedTable(embeddedTableKey, form, extParams, toText) {
      const { coreId, id, databaseId, databaseVersion } = this.subjectInfo
      const params = {
        projectId: localStorage.getItem('sys-project-id'),
        databaseId,
        databaseVersion,
        subjectId: id,
        coreId,
        environment: localStorage.getItem('environment'),
        embeddedTableName: embeddedTableKey,
        ...extParams,
      }
      if (this.tableStatus) {
        params.formDataId = this.tableStatus.formDataId
      }
      if (this.originSubjectData && this.originSubjectData.length > 0) {
        this.show = false
        this.$nextTick(() => {
          this.show = true
        })
      } else if (this.originSubjectData && this.originSubjectData[embeddedTableKey].length > 0) {
        if (this.isAddEm && !this.isAdd) {
          this.findEmbeddedTable(params, extParams, toText)
        } else {
          this.show = false
          this.$nextTick(() => {
            this.show = true
          })
        }
      } else {
        this.findEmbeddedTable(params, extParams, toText)
      }
    },

    // 内嵌表数据处理
    handleLaboratory(form) {
      let flag
      this.tableFieldList &&
        this.tableFieldList.forEach(tableField => {
          const { variable, variableValue, embeddedMust } = tableField
          if (typeof embeddedMust !== 'undefined') {
            const value = form[variable]
            if (value !== variableValue) {
              flag = true
            }
          }
        })
      if (flag) {
        this.tableFieldList &&
          this.tableFieldList.forEach(tableField => {
            const { type, embeddedTableKey, embeddedTableType, embeddedTableModuleName, embeddedTableVariableMapping } =
              tableField
            if (type === '3' && embeddedTableType === 2) {
              const { fieldValue } = this.tableFieldConfig.defaultValues.filter(
                object => object.tableField == embeddedTableModuleName
              )[0]
              this.reloadEmbeddedTable(embeddedTableKey, form, {
                embeddedTableType,
                embeddedTableModuleName,
                embeddedTableVariableMapping,
                embeddedTableVariableValue: fieldValue,
              })
            }
          })
      }
    },
    // 同步表单数据
    handleSynchronize(form) {
      this.tableFieldList &&
        this.tableFieldList.forEach(tableField => {
          const { type, variable, variableType, embeddedTableKey } = tableField
          if (type === '1') {
            const value = form[variable]
            if (variableType === '20') {
              if (value && value.length > 0) {
                tableField.variableValue = value.join(',')
              } else {
                tableField.variableValue = ''
              }
            } else {
              tableField.variableValue = value
            }
          } else if (type === '3') {
            if (!this.embeddedTable) {
              return
            }
            const embeddedTable = this.embeddedTable[embeddedTableKey]
            const f = form[embeddedTableKey]
            f &&
              embeddedTable &&
              embeddedTable.forEach((object, index) => {
                const { tableFieldList } = object
                tableFieldList &&
                  tableFieldList.forEach(tableField => {
                    const value = f[`${tableField.variable}--${index}`]
                    if (tableField.variableType === '20') {
                      if (value && value.length > 0) {
                        tableField.variableValue = value.join(',')
                      } else {
                        tableField.variableValue = ''
                      }
                    } else {
                      tableField.variableValue = value
                    }
                  })
              })
          }
        })
    },
    // 内嵌表处理行显示
    handleEmbeddedTable(tableField, form) {
      const { embeddedTableKey } = tableField
      if (form[embeddedTableKey] && this.embeddedTable) {
        const embeddedTable = this.embeddedTable[embeddedTableKey]
        embeddedTable &&
          embeddedTable.forEach((object, index) => {
            const { tableFieldList } = object
            this.handleDisplay(tableFieldList, form[embeddedTableKey], index)
          })
      }
    },
    handleMainTable(tableFieldList, tableField, form, index) {
      // 内嵌表数据处理
      const { variable, variableType, rowControl } = tableField
      if (rowControl && rowControl.length > 0) {
        let value
        if (typeof index === 'undefined') {
          value = form[variable]
        } else {
          value = form[`${variable}--${index}`]
        }
        if ((variableType === '10') || (variableType === '20')) {
          const rowControls = []
          const options = []
          rowControl.forEach(object => {
            let keys
            if (variableType === '10') {
              keys = Object.keys(object).filter(key => key == value)
            } else if (variableType === '20') {
              keys = Object.keys(object).filter(key => value.includes(key))
            }
            if (keys.length > 0) {
              options.push(object)
            }
            Object.values(object).forEach(value => {
              rowControls.push.apply(rowControls, value)
            })
          })
          if (rowControls.length > 0) {
            rowControls.forEach(variable => {
              tableFieldList &&
                tableFieldList.forEach(tableField => {
                  if (tableField.variable == variable || tableField.embeddedTableKey == variable) {
                    this.$set(tableField, 'controlled', true)
                    if (tableField.embeddedTableKey) {
                      this.embeddedTable &&
                        this.embeddedTable[tableField.embeddedTableKey].forEach(item => {
                          const { tableFieldList } = item
                          tableFieldList.forEach(el => {
                            this.$set(el, 'controlled', true)
                          })
                        })
                    }
                  }
                })
            })
          }
          if (options.length > 0) {
            if (variableType === '10') {
              options.forEach(option => {
                option[value] &&
                  option[value].forEach(variable => {
                    tableFieldList &&
                      tableFieldList.forEach(tableField => {
                        if (tableField.variable == variable || tableField.embeddedTableKey == variable) {
                          this.$set(tableField, 'controlled', false)
                          if (tableField.embeddedTableKey) {
                            this.embeddedTable &&
                              this.embeddedTable[tableField.embeddedTableKey].forEach(item => {
                                const { tableFieldList } = item
                                tableFieldList.forEach(el => {
                                  this.$set(el, 'controlled', false)
                                })
                              })
                          }
                        }
                      })
                  })
              })
            } else if (variableType === '20') {
              options.forEach(option => {
                value.forEach(v => {
                  option[v] &&
                    option[v].forEach(variable => {
                      tableFieldList &&
                        tableFieldList.forEach(tableField => {
                          if (tableField.variable == variable || tableField.embeddedTableKey == variable) {
                            this.$set(tableField, 'controlled', false)
                            if (tableField.embeddedTableKey) {
                              this.embeddedTable &&
                                this.embeddedTable[tableField.embeddedTableKey].forEach(item => {
                                  const { tableFieldList } = item
                                  tableFieldList.forEach(el => {
                                    this.$set(el, 'controlled', false)
                                  })
                                })
                            }
                          }
                        })
                    })
                })
              })
            }
          }
        }
      }
    },

    handleDisplay(tableFieldList, form, index) {
      this.initializeDisplay(tableFieldList)
      tableFieldList &&
        tableFieldList.forEach(tableField => {
          const { type, variableType } = tableField
          if ((type === '1' && ['10', '20'].includes(variableType)) || typeof type === 'undefined' || !type) {
            this.handleMainTable(tableFieldList, tableField, form, index)
          } else if (type === '3') {
            this.handleEmbeddedTable(tableField, form)
          }
        })
    },
    // 初始花表单显示字段controlled
    initializeDisplay(tableFieldList) {
      tableFieldList &&
        tableFieldList.forEach(tableField => {
          const { type, rowControl, embeddedTableKey } = tableField
          if (type === '1' || typeof type === 'undefined') {
            const rowControls = []
            if (rowControl && rowControl.length > 0) {
              rowControl.forEach(object => {
                Object.values(object).forEach(value => {
                  rowControls.push.apply(rowControls, value)
                })
              })
            }
            if (rowControls.length > 0) {
              rowControls.forEach(variable => {
                tableFieldList &&
                  tableFieldList.forEach(tableField => {
                    if (tableField.variable === variable || tableField.embeddedTableKey === variable) {
                      this.$set(tableField, 'controlled', true)
                      if (tableField.embeddedTableKey) {
                        this.embeddedTable &&
                          this.embeddedTable[tableField.embeddedTableKey].forEach(item => {
                            const { tableFieldList } = item
                            tableFieldList.forEach(el => {
                              this.$set(el, 'controlled', true)
                            })
                          })
                      }
                    }
                  })
              })
            }
          } else if (type === '3') {
            if (!this.embeddedTable) {
              return
            }
            const embeddedTable = this.embeddedTable[embeddedTableKey]
            embeddedTable &&
              embeddedTable.forEach(object => {
                const { tableFieldList } = object
                this.initializeDisplay(tableFieldList)
              })
          }
        })
    },
    handleAudits(variable, keywords, checked) {
      if (keywords === 'pi') {
        this.$set(this.form, `$${variable}--sign`, checked)
      } else {
        const { code } = this.relations.filter(relation => relation.alias == keywords)[0]
        const target = this.audits.filter(audit => audit.roleCode == code)[0]
        target && this.$set(this.form, `$${variable}--${target.tag}`, checked)
      }
    },
    createQuestion() {
      this.dialogQuestionVisible = false
      this.dialogAddQuestionVisible = true
    },
    async handleQuestion(e, tableField) {
      this.targetTableField = tableField
      const classList = e.currentTarget.classList
      for (let v of classList.values()) {
        if (v && v.startsWith('question-')) {
          const arr = v.split('-')
          if (arr[1] === '0' || arr[1] === '1') {
            return
          } else if (arr[1] === '5') {
            this.dialogAddQuestionVisible = true
            return
          }
        }
      }
      // 接口放到外面
      let params = { id: this.targetTableField.formFieldId }
      const res = await this.getQueryListAPI({ params })
      if (res.code === 200) {
        this.queryListData = res.data
        this.dialogQuestionVisible = true
      }
    },
    handleCloseNotes() {
      this.exParams = {}
      this.dataNotes = []
      this.dialogNotesVisible = false
    },
    closeDialogQuestion() {
      this.dialogQuestionVisible = false
      this.upgrade()
    },
    handleNotes(tableField) {
      if (!this.permissionController('crf::form::data::annotation')) {
        return
      }
      // 没有提交/保存就不能点击
      if (!tableField.formFieldId) {
        return
      }
      let flag
      if (this.tableStatus.isLapse === '1' && this.tableStatus.frozen === '1') {
        flag = true
      } else {
        flag = tableField.endorse != 0
      }
      if (flag) {
        this.findNotes(tableField)
        this.exParams = {
          tableField,
          detailsId: tableField.formFieldId,
          variableName: tableField.variableName,
          variableValue: tableField.variableValue,
        }
      }
    },
    findNotes(tableField) {
      const params = {
        detailsId: tableField.formFieldId,
        annotationType: '2',
      }
      this.annotationList({ params }).then(res => {
        const { code, data } = res
        if (code === 200) {
          this.dataNotes = data
          this.dialogNotesVisible = true
        }
      })
    },
    preHandle(tableFieldList) {
      if (tableFieldList && tableFieldList.length > 0) {
        return tableFieldList.filter(tableField => tableField.hide === '' || tableField.hide === '0')
      }
    },
    // 获取按钮状态
    handleQuestionStatus({ fromDataChecksetupDTO, formFieldId, question }) {
      if (this.tableStatus) {
        if (this.tableStatus.isStatus === '1') {
          return 1
        }
        let flag
        if (this.permissionController('send::challenge')) {
          flag = true
        }
        if (formFieldId) {
          if (question === 1) {
            if (flag) {
              if (this.tableStatus.isLapse === '1' && this.tableStatus.frozen === '1') {
                return 5
              } else {
                return 1
              }
            }
          } else if (question === 2) {
            if (
              this.permissionController('send::challenge') ||
              this.permissionController('subject::info::handle::challenge') ||
              this.permissionController('close::challenge')
            ) {
              return `${question}-2`
            } else {
              return `${question}-1`
            }
          }
          return question
        } else {
          return 1
        }
      } else {
        return 1
      }
    },
    // 渲染右侧按钮
    handleTools(value) {
      const result = []
      this.audits.forEach(audit => {
        const obj = {
          ...audit,
        }
        obj.disabled =
          audit.roleCode !== this.findRole ||
          !this.tableStatus ||
          this.tableStatus.isLapse === '2' ||
          this.tableStatus.isLapse === '3' ||
          this.tableStatus.isStatus === '1' ||
          this.tableStatus.frozen !== '1' ||
          !this.permissionController('crf::form::data::check')
        if (value && Object.keys(value).length > 0) {
          obj.enable = this.converter(audit, value)
        } else {
          obj.enable = 0
        }
        result.push(obj)
      })
      return result
    },
    converter(audit, value) {
      if (!value) {
        return 0
      }
      let result
      const { checkSetupOne, checkSetupTwo, checkSetupThree, checkSetupFour, checkSetupFive } = value
      switch (audit.sort) {
        case 1:
          result = checkSetupOne
          break
        case 2:
          result = checkSetupTwo
          break
        case 3:
          result = checkSetupThree
          break
        case 4:
          result = checkSetupFour
          break
        case 5:
          result = checkSetupFive
          break
      }

      return result
    },

    validate() {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate((valid, rule) => {
          if (valid) {
            resolve(true)
          } else {
            resolve(false)
          }
        })
      })
    },
  },
}
</script>

<style lang="scss" scoped>
@import './index';
</style>
